package com.qinghe.pro.controller.main;

import java.util.List;
import java.util.Map;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.qinghe.pro.entity.main.LogInfo;
import com.qinghe.pro.service.main.LogInfoService;
import com.qinghe.utils.AjaxObject;
import com.qinghe.utils.Page;

@Controller
@RequestMapping("/manager/logInfo")
public class LogInfoController {

	@Autowired
	@Qualifier("logInfoServiceImpl")
	private LogInfoService logInfoService;

	private static final String VIEW = "manager/logInfo/view";
	private static final String LIST = "manager/logInfo/list";

	@RequiresPermissions("LogInfo:delete")
	@RequestMapping(value = "/delete/{id}", method = RequestMethod.POST)
	public @ResponseBody AjaxObject delete(@PathVariable Integer id) {
		logInfoService.delete(id);

		return AjaxObject.newOk("删除系统日志成功！");
	}

	@RequiresPermissions("LogInfo:view")
	@RequestMapping(value = "/view/{id}", method = RequestMethod.GET)
	public String view(@PathVariable Integer id, Map<String, Object> map) {
		LogInfo logInfo = logInfoService.get(id);
		
		map.put("logInfo", logInfo);
		return VIEW;
	}

	@RequiresPermissions("LogInfo:show")
	@RequestMapping(value = "/list", method = { RequestMethod.GET, RequestMethod.POST })
	public String list(LogInfo logInfo, Page page, Map<String, Object> map) {
		List<LogInfo> logInfoList = logInfoService.findByPage(logInfo, page);

		map.put("page", page);
		map.put("logInfoList", logInfoList);

		return LIST;
	}

}
